package com.zhangqi.zhxa.utils;


import android.content.Context;
import android.content.SharedPreferences;

public class PrefUtils {

    //------------------放 boolean 值 ，取boolean 值------------------------------
    public static void putBoolean(String key,boolean value,Context ctx){
        SharedPreferences sp = ctx.getSharedPreferences("config",Context.MODE_PRIVATE);
        sp.edit().putBoolean(key,value).commit();
    }

    public static boolean getBoolean(String key,boolean defValue,Context ctx){
        SharedPreferences sp = ctx.getSharedPreferences("config",Context.MODE_PRIVATE);
        return sp.getBoolean(key,defValue);
    }

    //------------------放 String 值 ，取String 值------------------------------
    public static void putString(String key,String value,Context ctx){
        SharedPreferences sp = ctx.getSharedPreferences("config",Context.MODE_PRIVATE);
        sp.edit().putString(key,value).commit();
    }

    public static String getString(String key,String defValue,Context ctx){
        SharedPreferences sp = ctx.getSharedPreferences("config",Context.MODE_PRIVATE);
        return sp.getString(key,defValue);
    }

    //------------------放 Int 值 ，取Int 值------------------------------
    public static void putInt(String key,int value,Context ctx){
        SharedPreferences sp = ctx.getSharedPreferences("config",Context.MODE_PRIVATE);
        sp.edit().putInt(key,value).commit();
    }

    public static int getInt(String key,int defValue,Context ctx){
        SharedPreferences sp = ctx.getSharedPreferences("config",Context.MODE_PRIVATE);
        return sp.getInt(key,defValue);
    }

    //--------------------------remove-----------------------------------
    public static void remove(String key,Context ctx){
        SharedPreferences sp = ctx.getSharedPreferences("config",Context.MODE_PRIVATE);
        sp.edit().remove(key).commit();
    }
}










